package name.fowler.refactoring.simplestore.calculator;

import java.util.Collection;

import name.fowler.refactoring.simplestore.domain.PriceCodes;
import name.fowler.refactoring.simplestore.domain.Rental;

public class SimpleFreqPointCalculator implements FreqPointCalculator {

	/* (non-Javadoc)
	 * @see name.fowler.refactoring.simplestore.calculator.FreqPointCalculator#calculateRentalFreqPointForAll(java.util.Collection)
	 */
	public int calculateRentalFreqPointForAll(Collection<Rental> rentals) {
		int result = 0;
		for (Rental rental : rentals) {
			result += calculateRentalFreqPoint(rental);
		}
		return result;
	}
	
	/* (non-Javadoc)
	 * @see name.fowler.refactoring.simplestore.calculator.FreqPointCalculator#calculateRentalFreqPoint(name.fowler.refactoring.simplestore.Rental)
	 */
	public int calculateRentalFreqPoint(Rental rental){
		boolean isNewRelease = rental.getMovie().getPriceCode() == PriceCodes.NewRelease;
		boolean isRentedMoreOneDay = rental.getDaysRented() > 1;
		return isNewRelease && isRentedMoreOneDay ? 2 : 1;
	}
}
